package com.xuef.util;

import com.xuef.base.Cons;

/**
 * Created by moveb on 2018/5/21.
 */
public class RedisKeyGenerateUtil {
    private static String SPLIT = ":";
    private static String BIZ_LIKE = "LIKE";
    private static String BIZ_DISLIKE = "DISLIKE";

    private static String BIZ_EVENT = "EVENT";

    // 博客文章阅读量
    private static String READ_COUNT = "PV";

    // 用户关注的内容
    private static String OBSERVE = "OBSERVE";

    /**
     * 获取用户关注的博客文章列表的 redis key
     * @param userId
     * @return
     */
    public static String getObserveBlogsKey(int userId){
        return getKey(OBSERVE, Cons.ENTITY_TYPE.ENTITY_BLOG, userId);
    }

    /**
     * 获取用户关注的 用户列表的 redis key
     * @param userId
     * @return
     */
    public static String getObserveUsersKey(int userId){
        return  getKey(OBSERVE, Cons.ENTITY_TYPE.ENTITY_USER, userId);
    }

    public static String getEventQueueKey() {
        return BIZ_EVENT;
    }

    public static String getKey(String type, int entityType, int entityId){
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(type).append(SPLIT)
                .append(entityType).append(SPLIT)
                .append(entityId);
        return stringBuilder.toString();
    }

    /**
     * 返回某篇博文在redis中的阅读量的key
     * 如 blog: 1, 其key 为 PV:1:1
     * @param entityId
     * @return
     */
    public static String getPvKey(int entityId){
        return getKey(READ_COUNT,Cons.ENTITY_TYPE.ENTITY_BLOG,entityId);
    }

    public static String getBizDislike() {
        return BIZ_DISLIKE;
    }

    public static void setBizDislike(String bizDislike) {
        BIZ_DISLIKE = bizDislike;
    }

    public static String getBizLike() {
        return BIZ_LIKE;
    }

    public static void setBizLike(String bizLike) {
        BIZ_LIKE = bizLike;
    }

    public static String getSPLIT() {
        return SPLIT;
    }

    public static void setSPLIT(String SPLIT) {
        RedisKeyGenerateUtil.SPLIT = SPLIT;
    }
}
